home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / imap / ANSI / c-client / os_mnt.c < prev    next >
C/C++ Source or Header  |  1995-06-27  |  6KB  |  233 lines

  1. /*
  2.  * Program:    Operating-system dependent routines -- Mint version
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        6158 Lariat Loop NE
  6.  *        Bainbridge Island, WA  98110-2098
  7.  *        Internet: MRC@Panda.COM
  8.  *
  9.  * Date:    23 December 1993
  10.  * Last Edited:    26 June 1995
  11.  *
  12.  * Copyright 1995 by Mark Crispin
  13.  *
  14.  *  Permission to use, copy, modify, and distribute this software and its
  15.  * documentation for any purpose and without fee is hereby granted, provided
  16.  * that the above copyright notice appears in all copies and that both the
  17.  * above copyright notices and this permission notice appear in supporting
  18.  * documentation, and that the name of Mark Crispin not be used in advertising
  19.  * or publicity pertaining to distribution of the software without specific,
  20.  * written prior permission.  This software is made available "as is", and
  21.  * MARK CRISPIN DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO
  22.  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF
  23.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL
  24.  * MARK CRISPIN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  25.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  26.  * WHETHER IN AN ACTION OF CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT
  27.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  28.  * THIS SOFTWARE.
  29.  *
  30.  */
  31.  
  32. #include <ctype.h>
  33. #include <stdio.h>
  34. #include <MacTCPCommonTypes.h>
  35. #include <AddressXlation.h>
  36. #include <TCPPB.h>
  37. #include <Files.h>
  38. #include <SegLoad.h>
  39. #include <Strings.h>
  40. #include <Script.h>
  41. #include "tcp_mac.h"        /* must be before osdep.h */
  42. #include "mail.h"
  43. #include "osdep.h"
  44. #include "misc.h"
  45. #include <limits.h>
  46. #include <time.h>
  47. #include <pwd.h>
  48. #include <sys/stat.h>
  49. #include <errno.h>
  50. extern int errno;        /* just in case */
  51. #include <osbind.h>
  52.  
  53. struct hostent {
  54.   char *h_name;            /* official name of host */
  55.   char **h_aliases;        /* alias list */
  56.   int h_addrtype;        /* host address type */
  57.   int h_length;            /* length of address */
  58.   char **h_addr_list;        /* list of addresses from name server */
  59. #define    h_addr h_addr_list[0]    /* address, for backward compatiblity */
  60. };
  61.  
  62. struct hostent *gethostbyname (char *name); 
  63.  
  64. #define pascal
  65.  
  66. short TCPdriver = 0;        /* MacTCP's reference number */
  67. short resolveropen = 0;        /* TCP's resolver open */
  68.  
  69. #include "env_unix.c"
  70. #include "fs_mac.c"
  71. #include "ftl_mac.c"
  72. #include "nl_mac.c"
  73. #include "tcp_mac.c"
  74. #include "tz_nul.c"
  75. #include "gethstid.c"
  76. #include "writevs.c"
  77.  
  78. #define SIG_A5 0x41352020 /* 'A5  ' */
  79. #define SIG_SP 0x53502020 /* 'SP  ' */
  80. #define SIG_SVAR 0x53564152 /* 'SVAR' */
  81.  
  82. void *saveda5 asm("saveda5");
  83.  
  84. void *savedsp asm("savedsp");
  85.  
  86. struct sysvar {
  87.   long rwabs;
  88.   long mediach;
  89.   long getbpb;
  90.   long drvmap;
  91.   long timer;
  92.   long vbl;
  93.   long sysbase;
  94.   long hz200;
  95.   long logbase;
  96.   long ticks;
  97.   long vbls;
  98.   long vblq;
  99.   long five;
  100.   long put_vector;
  101.   long pull_vector;
  102.   struct {
  103.     long buf[20];
  104.   } procinfo;
  105.   long term;
  106.   long crit;
  107.   long resvec;
  108.   long resval;
  109. } *sysvar;
  110.  
  111. static long ssp;
  112.  
  113. void mint_setup (void)
  114. {
  115.   long w,*p;
  116.   return;            /* **temp** */
  117.   ssp = (long) Super ((long) 0);
  118.   for (p = *(long **) 0x5a0L; w = *p; p += 2) switch (w) {
  119.   case SIG_A5: saveda5 = (void *) p[1]; break;
  120.   case SIG_SP: savedsp = (void *) p[1]; break;
  121.   case SIG_SVAR: sysvar = (struct sysvar *) p[1]; break;
  122.   }
  123.   (*(void (*) (void)) sysvar->pull_vector) ();
  124. }
  125.  
  126. void mint_cleanup (void)
  127. {
  128.   return;            /* **temp** */
  129.                 /* clean up resolver */
  130.   if (resolveropen) CloseResolver ();
  131.   (*(void (*) (void)) sysvar->put_vector) ();
  132.   Super ((void *) ssp);
  133. }
  134.  
  135. /* Emulator for BSD fsync() call
  136.  * Accepts: file name
  137.  * Returns: 0 if successful, -1 if failure
  138.  */
  139.  
  140. int fsync (int fd)
  141. {
  142.   return (0);
  143. }
  144.  
  145.  
  146. /* Emulator for BSD ftruncate() call
  147.  * Accepts: file descriptor
  148.  * Returns: 0 if successful, -1 if failure
  149.  */
  150.  
  151. int ftruncate (int fd,off_t length)
  152. {
  153.   fatal ("oops, ftruncate() called!");
  154.   errno = EINVAL;
  155.   return -1;
  156. }
  157.  
  158. /* Emulator for BSD gethostbyname() call
  159.  * Accepts: host name
  160.  * Returns: hostent struct if successful, 0 if failure
  161.  */
  162.  
  163. static struct hostent ghostent;
  164. struct hostInfo ghostinf;
  165.  
  166. struct hostent *gethostbyname (char *host)
  167. {                /* init MacTCP and resolver */
  168.   if ((!TCPdriver && OpenDriver ("\04.IPP",&TCPdriver)) ||
  169.       (!resolveropen && OpenResolver (NIL))) return NIL;
  170.   resolveropen = T;        /* note resolver open now */
  171.   if (StrToAddr (host,&ghostinf,tcp_dns_result,NIL)) {
  172.     while (ghostinf.rtnCode == cacheFault && wait ());
  173.                 /* kludge around MacTCP bug */
  174.     if (ghostinf.rtnCode == outOfMemory) {
  175.       mm_log ("Re-initializing domain resolver",WARN);
  176.       CloseResolver ();        /* bop it on the head and try again */
  177.       OpenResolver (NIL);    /* note this will leak 12K */
  178.       StrToAddr (host,&ghostinf,tcp_dns_result,NIL);
  179.       while (ghostinf.rtnCode == cacheFault && wait ());
  180.     }
  181.     if (ghostinf.rtnCode) return NIL;
  182.   }
  183.   ghostent.h_name = ghostinf.cname;
  184.   ghostent.h_aliases = NIL;    /* kludge other stuff - may do more later */
  185.   ghostent.h_addrtype = 0;
  186.   ghostent.h_length = 0;
  187.   ghostent.h_addr_list = NIL;
  188.   return &ghostent;        /* return the data */
  189. }
  190.  
  191. /* Open driver (should be in Mac library, but...)
  192.  * Accepts: driver name
  193.  *        pointer to driver reference number return location
  194.  * Returns: 0 if success, reference number returned
  195.  */
  196.  
  197. OSErr OpenDriver (ConstStr255Param name,short *drvrRefNum)
  198. {
  199.   OSErr err;
  200.   ParamBlockRec pb;
  201.   return -1; /* ***temp*** until can make toolkit calls work */
  202.                 /* driver name */
  203.   pb.ioParam.ioNamePtr = (StringPtr) name;
  204.                 /* read/write shared permission */
  205.   pb.ioParam.ioPermssn = fsCurPerm;
  206.   err = PBOpenSync (&pb);    /* do the open */
  207.   *drvrRefNum = pb.ioParam.ioRefNum;
  208.   return err;
  209. }
  210.  
  211.  
  212. /* Get working directory Info (should be in Mac library, but...)
  213.  * Accepts: working directory to query
  214.  *        pointer to ref num of working directory's volume
  215.  *        pointer to directory ID of working directory return location
  216.  *        if !=0, index specific working directories
  217.  * Returns: 0 if success, reference number returned
  218.  */
  219.  
  220. extern OSErr GetWDInfo (short wdRefNum,short *vRefNum,long *dirID,long *procID)
  221. {
  222.   OSErr err;
  223.   WDPBRec pb;
  224.   pb.ioWDVRefNum = wdRefNum;
  225.   pb.ioVRefNum = *vRefNum;
  226.   pb.ioWDProcID = *procID;
  227.   err = PBGetWDInfoSync (&pb);    /* do the get wd info */
  228.   *vRefNum = pb.ioVRefNum;
  229.   *dirID = pb.ioWDDirID;
  230.   *procID = pb.ioWDProcID;
  231.   return err;
  232. }
  233.